package com.situ.allaia.controller;

import com.situ.allaia.model.User;
import com.situ.allaia.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {
    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/list")
    public String list(){
        return "user/list";
    }

    @GetMapping("/add")
    public String add(){
        return "user/add";
    }
    @GetMapping("/edit")
    public String edit(Integer id, Map<String,Object> map){
        User user = userService.findById(id);
        if (user == null){
            map.put("error","要修改的用户不存在");
        }else{
            map.put("user",user);
        }
        return "user/edit";
    }
}
